package com.library.web.controller.library;


import com.library.common.annotation.Log;
import com.library.common.core.controller.BaseController;
import com.library.common.core.domain.AjaxResult;
import com.library.common.core.page.TableDataInfo;
import com.library.common.enums.BusinessType;
import com.library.common.utils.poi.ExcelUtil;
import com.library.domain.MbGiftConvert;
import com.library.service.IMbGiftConvertService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 礼品兑换 信息操作处理
 *
 * @author null
 * @date 2020-04-23
 * @blame Android Team
 */
@Slf4j
@RestController
@RequestMapping("/library/mbGiftConvert")
public class MbGiftConvertController extends BaseController {

    @Autowired
    private IMbGiftConvertService mbGiftConvertService;

    /**
     * 查询礼品兑换列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:list')")
    @GetMapping("/list")
    public TableDataInfo list(MbGiftConvert mbGiftConvert) {
        startPage();
        List<MbGiftConvert> list = mbGiftConvertService.selectMbGiftConvertList(mbGiftConvert);
        return getDataTable(list);
    }

    /**
     * 导出礼品兑换列表
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:export')")
    @Log(title = "礼品兑换", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MbGiftConvert mbGiftConvert) {
        List<MbGiftConvert> list = mbGiftConvertService.selectMbGiftConvertList(mbGiftConvert);
        ExcelUtil<MbGiftConvert> util = new ExcelUtil<>(MbGiftConvert.class);
        util.exportExcel(response, list, "礼品兑换数据");
    }

    /**
     * 获取礼品兑换详细信息
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mbGiftConvertService.selectMbGiftConvertById(id.intValue()));
    }

    /**
     * 新增礼品兑换
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:add')")
    @Log(title = "礼品兑换", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MbGiftConvert mbGiftConvert) {
        return toAjax(mbGiftConvertService.insertMbGiftConvert(mbGiftConvert));
    }

    /**
     * 修改礼品兑换
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:edit')")
    @Log(title = "礼品兑换", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MbGiftConvert mbGiftConvert) {
        return toAjax(mbGiftConvertService.updateMbGiftConvert(mbGiftConvert));
    }

    /**
     * 删除礼品兑换
     */
    @PreAuthorize("@ss.hasPermi('library:mbGiftConvert:remove')")
    @Log(title = "礼品兑换", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mbGiftConvertService.deleteMbGiftConvertByIds(ids));
    }
}
